(function ($) {
    $.fn.extend({
        dscroll: function (options) {
            var defaults = {
                stopitem: '',
                positionafter: 'static'
            }
            var options = $.extend(defaults, options);
            return this.each(function () {
                var o = options;
                var el = $(this);
                var stopdiv = o.stopitem;
                if ( !! el.length) {
                    var stickyTop = el.offset().top;
                    if (stopdiv) {
                        var footerTop = $(stopdiv).offset().top;
                        var stickyHeight = el.height();
                        var limit = footerTop - stickyHeight;
                    } else {
                        var footerTop = 0;
                    }
                    $(window).scroll(function () {
                        var windowTop = $(window).scrollTop();
                        if (stickyTop < windowTop) {
                            el.css({
                                position: 'fixed',
                                top: 10
                            });
                        } else {
                            el.css('position', o.positionafter);
                        }
                        if (limit < windowTop) {
                            var diff = limit - windowTop;
                            el.css({
                                top: diff
                            });
                        }
                    });
                }
            });
        }
    });
})(jQuery);

(function ($, document, undefined) {
    var pluses = /\+/g;

    function raw(s) {
        return s;
    }

    function decoded(s) {
        return decodeURIComponent(s.replace(pluses, ' '));
    }
    var config = $.cookie = function (key, value, options) {
            if (value !== undefined) {
                options = $.extend({}, config.defaults, options);
                if (value === null) {
                    options.expires = -1;
                }
                if (typeof options.expires === 'number') {
                    var days = options.expires,
                        t = options.expires = new Date();
                    t.setDate(t.getDate() + days);
                }
                value = config.json ? JSON.stringify(value) : String(value);
                return (document.cookie = [encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : ''].join(''));
            }
            var decode = config.raw ? raw : decoded;
            var cookies = document.cookie.split('; ');
            for (var i = 0, parts;
            (parts = cookies[i] && cookies[i].split('=')); i++) {
                if (decode(parts.shift()) === key) {
                    var cookie = decode(parts.join('='));
                    return config.json ? JSON.parse(cookie) : cookie;
                }
            }
            return null;
        };
    config.defaults = {};
    $.removeCookie = function (key, options) {
        if ($.cookie(key) !== null) {
            $.cookie(key, null, options);
            return true;
        }
        return false;
    };
})(jQuery, document);

(function ($) {
    $.fn.jsonSuggest = function (settings) {
        var defaults = {
            url: '',
            data: [],
            minCharacters: 1,
            maxResults: undefined,
            wildCard: '',
            caseSensitive: false,
            notCharacter: '!',
            maxHeight: undefined,
            highlightMatches: true,
            onSelect: undefined,
            width: undefined
        },
            getJSONTimeout;
        settings = $.extend(defaults, settings);
        return this.each(function () {
            function regexEscape(txt, omit) {
                var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'];
                if (omit) {
                    for (var i = 0; i < specials.length; i++) {
                        if (specials[i] === omit) {
                            specials.splice(i, 1);
                        }
                    }
                }
                var escapePatt = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
                return txt.replace(escapePatt, '\\$1');
            }
            var obj = $(this),
                wildCardPatt = new RegExp(regexEscape(settings.wildCard || ''), 'g'),
                results = $('<ul />'),
                currentSelection, pageX, pageY;

            function selectResultItem(item) {
                obj.val(item.text);
                $(results).html('').hide();
                if (typeof settings.onSelect === 'function') {
                    settings.onSelect(item);
                }
            }

            function setHoverClass(el) {
                $('li', results).removeClass('ui-state-hover');
                if (el) {
                    $(el).addClass('ui-state-hover');
                }
                currentSelection = el;
            }

            function buildResults(resultObjects, filterTxt) {
                filterTxt = '(' + filterTxt + ')';
                var bOddRow = true,
                    i, iFound = 0,
                    filterPatt = settings.caseSensitive ? new RegExp(filterTxt, 'g') : new RegExp(filterTxt, 'ig');
                $(results).html('').hide();
                for (i = 0; i < resultObjects.length; i += 1) {
                    var item = $('<li />'),
                        text = resultObjects[i].text,
                        link = resultObjects[i].link,
                        price = resultObjects[i].price;
                    if (settings.highlightMatches === true) {
                        text = text.replace(filterPatt, '<strong>$1</strong>');
                    }
                    $(item).append('<a class="ui-corner-all" href="' + link + '"><span class="text_suggest">' + text + '</span><p>' + price + '</p><div class="fix"></div></a>');
                    if (typeof resultObjects[i].image === 'string') {
                        $('>a', item).prepend('<img src="' + resultObjects[i].image + '" />');
                    }
                    if (typeof resultObjects[i].extra === 'string') {
                        $('>a', item).append('<small>' + resultObjects[i].extra + '</small>');
                    }
                    if (typeof resultObjects[i].price === 'string') {
                        $('>atext_suggest', item).append('<small>' + resultObjects[i].price + '</small>');
                    }
                    $(item).addClass('ui-menu-item').addClass((bOddRow) ? 'odd' : 'even').attr('role', 'menuitem').click((function (n) {
                        return function () {
                            selectResultItem(resultObjects[n]);
                        };
                    })(i)).mouseover((function (el) {
                        return function () {
                            setHoverClass(el);
                        };
                    })(item));
                    $(results).append(item);
                    bOddRow = !bOddRow;
                    iFound += 1;
                    if (typeof settings.maxResults === 'number' && iFound >= settings.maxResults) {
                        break;
                    }
                }
                if ($('li', results).length > 0) {
                    currentSelection = undefined;
                    $(results).show().css('height', 'auto');
                    if ($(results).height() > settings.maxHeight) {
                        $(results).css({
                            'overflow': 'hidden',
                            'height': settings.maxHeight + 'px'
                        });
                    }
                }
            }

            function runSuggest(e) {
                var search = function (searchData) {
                        if (this.value.length < settings.minCharacters) {
                            $(results).html('').hide();
                            return false;
                        }
                        var resultObjects = [],
                            filterTxt = (!settings.wildCard) ? regexEscape(this.value) : regexEscape(this.value, settings.wildCard).replace(wildCardPatt, '.*'),
                            bMatch = true,
                            filterPatt, i;
                        if (settings.notCharacter && filterTxt.indexOf(settings.notCharacter) === 0) {
                            filterTxt = filterTxt.substr(settings.notCharacter.length, filterTxt.length);
                            if (filterTxt.length > 0) {
                                bMatch = false;
                            }
                        }
                        filterTxt = filterTxt || '.*';
                        filterTxt = settings.wildCard ? '^' + filterTxt : filterTxt;
                        filterPatt = settings.caseSensitive ? new RegExp(filterTxt) : new RegExp(filterTxt, 'i');
                        for (i = 0; i < searchData.length; i += 1) {
                            if (filterPatt.test(searchData[i].text) === bMatch) {
                                resultObjects.push(searchData[i]);
                            }
                        }
                        buildResults(resultObjects, filterTxt);
                    };
                if (settings.data && settings.data.length) {
                    search.apply(this, [settings.data]);
                } else if (settings.url && typeof settings.url === 'string') {
                    var text = this.value;
                    if (text.length < settings.minCharacters) {
                        $(results).html('').hide();
                        return false;
                    }
                    $(results).html('<li class="ui-menu-item ajaxSearching"><span></span></li>').show().css('height', 'auto');
                    getJSONTimeout = window.clearTimeout(getJSONTimeout);
                    getJSONTimeout = window.setTimeout(function () {
                        $.getJSON(settings.url, {
                            search: text
                        }, function (data) {
                            if (data) {
                                buildResults(data, text);
                            } else {
                                $(results).html('').hide();
                            }
                        });
                    }, 500);
                }
            }

            function keyListener(e) {
                switch (e.keyCode) {
                case 13:
                    $(currentSelection).trigger('click');
                    return false;
                case 40:
                    if (typeof currentSelection === 'undefined') {
                        currentSelection = $('li:first', results).get(0);
                    } else {
                        currentSelection = $(currentSelection).next().get(0);
                    }
                    setHoverClass(currentSelection);
                    if (currentSelection) {
                        $(results).scrollTop(currentSelection.offsetTop);
                    }
                    return false;
                case 38:
                    if (typeof currentSelection === 'undefined') {
                        currentSelection = $('li:last', results).get(0);
                    } else {
                        currentSelection = $(currentSelection).prev().get(0);
                    }
                    setHoverClass(currentSelection);
                    if (currentSelection) {
                        $(results).scrollTop(currentSelection.offsetTop);
                    }
                    return false;
                default:
                    runSuggest.apply(this, [e]);
                }
            }
            $(results).addClass('jsonSuggest ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all').attr('role', 'listbox').css({
                'top': (obj.position().top + obj.outerHeight()) + 'px',
                'left': obj.position().left + 'px',
                'width': settings.width || (obj.outerWidth() + 'px'),
                'z-index': 1500
            }).hide();
            obj.after(results).keyup(keyListener).keydown(function (e) {
                if (e.keyCode === 9 && currentSelection) {
                    $(currentSelection).trigger('click');
                    return true;
                }
            }).blur(function (e) {
                var resPos = $(results).offset();
                resPos.bottom = resPos.top + $(results).height();
                resPos.right = resPos.left + $(results).width();
                if (pageY < resPos.top || pageY > resPos.bottom || pageX < resPos.left || pageX > resPos.right) {
                    $(results).hide();
                }
            }).focus(function (e) {
                $(results).css({
                    'top': (obj.position().top + obj.outerHeight()) + 'px',
                    'left': obj.position().left + 'px'
                });
                if ($('li', results).length > 0) {
                    $(results).show();
                }
            }).attr('autocomplete', 'off');
            $(window).mousemove(function (e) {
                pageX = e.pageX;
                pageY = e.pageY;
            });
            settings.notCharacter = regexEscape(settings.notCharacter || '');
            if (settings.data && typeof settings.data === 'string') {
                settings.data = $.parseJSON(settings.data);
            }
        });
    };
})(jQuery);

$(function () {
    $('.select_zone a').click(function () {
        var tm;
        var href;
        var elem = $(this);
        var cookie_value = elem.attr('rel').replace(/\D/g, '');
        var zone_name = elem.html();
        if (cookie_value == 52) {
            href = 'TPHoChiMinh';
        } else {
            href = 'HaNoi';
        }
        $('a#zoneLabel').html('<b class="iconCity"> ' + zone_name + '</b><span class="iconCity-arr">&nbsp;</span>');
        $.cookie('zone_cookie', cookie_value, {
            expires: 365,
            path: '/'
        });
        $('#sub-zone-select').removeClass('open');
        return false;
    });
    if ($.fn.livequery) {
        $('.close').livequery('click', function () {
            $(this).parent().hide();
        });
    } else {
        $('.close').click(function () {
            $(this).parent().hide();
        });
    }
    $('input#searchboxInput').jsonSuggest({
        url: 'ajax/frontend/suggest_ajax?zone=' + $.cookie('zone_cookie'),
        maxResults: 7,
        minCharacters: 2,
        width: 550,
        onSelect: callback
    });
    $('.open-popup-login').click(function () {
        $('.login-mask').fadeIn(200);
        $('.popup-login').show();
        return false;
    });
    $('.close-popup-login, .login-mask').click(function () {
        $('.login-mask').fadeOut(200);
        $('.popup-login').fadeOut(200);
        $('#login_form input[type="text"]').val('');
        $('.login-result, .login-cdt-result').html('');
        return false;
    });
    $('.login-click').click(function (e) {
        e.preventDefault();
        $('form#login_form').submit();
        return false;
    });
    $('form#login_form').submit(function () {
        var data = $(this).serialize();
        $.ajax({
            beforeSend: function () {
                $('.loading-element').removeClass('hide');
                $('.login-click').attr('disabled', 'disabled');
            },
            url: 'ajax/frontend/user_ajax/login',
            type: 'post',
            data: data,
            dataType: 'json',
            success: function (data) {
                $('.loading-element').addClass('hide');
                $('.login-click').removeAttr('disabled');
                if (data.err == 1) {
                    $('.login-result').html(data.msg);
                } else if (data.err == 0) {
                    $('.popup-login').hide();
                    location.reload();
                }
            }
        });
        return false;
    });
    $('.icon-sCDT').click(function () {
        $('form#login_form').slideUp(200);
        $('form#cdt_form').slideDown(200);
        return false;
    });
    $('.login_back').click(function () {
        $('form#login_form').slideDown(200);
        $('form#cdt_form').slideUp(200);
        return false;
    });
    $('.login-cdt-click').click(function (e) {
        e.preventDefault();
        $('form#cdt_form').submit();
        return false;
    });
    $('form#cdt_form').submit(function () {
        var data = $(this).serialize();
        $.ajax({
            beforeSend: function () {
                $('.loading-element').removeClass('hide');
                $('.login-cdt-click').attr('disabled', 'disabled');
            },
            url: 'ajax/frontend/user_ajax/cdt_login',
            type: 'post',
            data: data,
            dataType: 'json',
            success: function (data) {
                $('.loading-element').addClass('hide');
                $('.login-cdt-click').removeAttr('disabled');
                if (data.err == 1) {
                    $('.login-cdt-result').html(data.msg);
                } else if (data.err == 0) {
                    $('.popup-login').hide();
                    location.reload();
                }
            }
        });
        return false;
    });
    $('.fb-login').click(function (e) {
        e.preventDefault();
        $.ajax({
            beforeSend: function () {
                $('.loading-element').removeClass('hide');
            },
            url: 'ajax/frontend/user_ajax/fb_login',
            type: 'get',
            data: {},
            dataType: 'json',
            success: function (data) {
                $('.loading-element').addClass('hide');
                if (data.mode == 'login') {
                    window.location = data.login_url;
                }
            }
        });
        return false;
    });
    $('form#login_page_form').submit(function () {
        var data = $(this).serialize();
        $.ajax({
            beforeSend: function () {
                $('.login-page-click').attr('disabled', 'disabled');
            },
            url: 'ajax/frontend/user_ajax/login',
            type: 'post',
            data: data,
            dataType: 'json',
            success: function (data) {
                $('.login-page-click').removeAttr('disabled');
                if (data.err == 1) {
                    $('.login-page-result').html(data.msg);
                } else if (data.err == 0) {
                    location.href = data.return_url;
                }
            }
        });
        return false;
    });
    $('form#login_cdt_page_form').submit(function () {
        var data = $(this).serialize();
        $.ajax({
            beforeSend: function () {
                $('.login-cdt-click').attr('disabled', 'disabled');
            },
            url: 'ajax/frontend/user_ajax/cdt_login',
            type: 'post',
            data: data,
            dataType: 'json',
            success: function (data) {
                $('.login-cdt-click').removeAttr('disabled');
                if (data.err == 1) {
                    $('.login-cdt-page-result').html(data.msg);
                } else if (data.err == 0) {
                    location.href = data.return_url;
                }
            }
        });
        return false;
    });
    $('.acc-CDT').click(function () {
        $('#login_page_form').hide();
        $('#login_cdt_page_form').fadeIn(200);
        return false;
    });
    $('.login_page_back').click(function () {
        $('#login_cdt_page_form').hide();

        $('#login_page_form').fadeIn(200);
        return false;
    });
    $('form#register_form').submit(function () {
        var data = $(this).serialize();
        var tm;
        $.ajax({
            beforeSend: function () {
                $('.register-click').attr('disabled', 'disabled');
            },
            url: 'ajax/frontend/user_ajax/register',
            type: 'post',
            data: data,
            dataType: 'json',
            success: function (data) {
                $('.register-click').removeAttr('disabled');
                if (data.err == 1) {
                    $('.register-result').html(data.msg);
                } else if (data.err == 0) {
                    $('.register-result').html(data.msg);
                    window.clearTimeout(tm);
                    tm = setTimeout(function () {
                        location.href = data.return_url;
                    }, 1500);
                }
            }
        });
        return false;
    });
    $('#zone_list').change(function () {
        var elem = $(this);
        var zone_id = elem.val();
        $.ajax({
            beforeSend: function () {
                elem.addClass('disabled');
            },
            url: 'ajax/location_ajax/load_district',
            type: 'get',
            data: {
                'zone_id': zone_id
            },
            success: function (data) {
                $('#district_list').html(data);
            }
        });
    });
    $('.show-recover').click(function () {
        $('#recover_form').toggleClass('elem-hide');
        return false;
    });
    $('form#recover_form').submit(function () {
        var data = $(this).serialize();
        $.ajax({
            beforeSend: function () {
                $('.recover-click').attr('disabled', 'disabled');
            },
            url: 'ajax/frontend/user_ajax/recover',
            type: 'post',
            data: data,
            dataType: 'json',
            success: function (data) {
                $('.recover-click').removeAttr('disabled');
                if (data.err == 1) {
                    $('.recover-result').html(data.msg);
                } else if (data.err == 0) {
                    $('.recover-result').html('');
                    $('.recover-click').attr('disabled', 'disabled');
                    $('.recover-success').html(data.msg);
                }
            }
        });
        return false;
    });
    $('form#recover_pass_form').submit(function () {
        var data = $(this).serialize();
        $.ajax({
            beforeSend: function () {
                $('.recover-pass-click').attr('disabled', 'disabled');
            },
            url: 'ajax/frontend/user_ajax/recover_pass',
            type: 'post',
            data: data,
            dataType: 'json',
            success: function (data) {
                $('.recover-pass-click').removeAttr('disabled');
                if (data.err == 1) {
                    $('.recover-pass-result').html(data.msg);
                } else if (data.err == 0) {
                    location.href = data.return_url;
                }
            }
        });
        return false;
    });
    $('.onetop_scroll2').dscroll({
        positionafter: 'absolute',
        stopitem: '.footer'
    });
});
$('#login_form').keyup(function (e) {
    if (e.keyCode == 13) {
        e.preventDefault();
        $('form#login_form').submit();
    }
});
$('#cdt_form').keyup(function (e) {
    if (e.keyCode == 13) {
        e.preventDefault();
        $('form#cdt_form').submit();
    }
});
$('#login_page_form').keyup(function (e) {
    if (e.keyCode == 13) {
        e.preventDefault();
        $('form#login_page_form').submit();
    }
});
$(document).keyup(function (e) {
    if (e.keyCode == 27) {
        e.preventDefault();
        $('.login-mask').fadeOut(200);
        $('.popup-login').fadeOut(200);
        $('#login_form input[type="text"]').val('');
        $('.login-result, .login-cdt-result').html('');
        return false;
    }
});

function callback(item) {
    location.href = item.link;
    $('#searchboxInput').val('');
}

function scroll_notice(name) {
    $('html,body').animate({
        scrollTop: $("." + name).offset().top
    }, 800);
}
$(window).scroll(function () {
    var scroll_height = $(window).scrollTop();
    if (scroll_height > 400) {
        $('.gotop').fadeIn(200);
    } else {
        $('.gotop').fadeOut(200);
    }
});

var min_angle = 60;
var coordinates = [{
    'x': 0,
    'y': 0
}];
var mousestep = 10;
$(function () {
    var great_dad = $('#flyout');
    var parent_cat = $('#wrap-parent');
    var sub_cat = $('#wrap-child');
    var nav_timeout;
    var flyoutcomplete = function () {}
    var flyout = function () {
            sub_cat.show();
            sub_cat.stop().animate({
                width: 528
            }, {
                duration: "fast",
            }).css({
                'overflow': 'visible'
            });
        }
    var hide_all = function (mode) {
            sub_cat.css({
                width: 0
            });
            sub_cat.hide();
        }
    $('.sub-level1').mousemove(function (e) {
        add_coordinates({
            'x': e.pageX,
            'y': e.pageY
        });
    });
    $("#wrap-parent li.par_cat").hover(function () {
        window.clearTimeout(nav_timeout);
        var match = /^nav_cat_(.+)/.exec(this.id);
        var cat = (match ? match[1] : "");
        var angle = get_angel(coordinates[0], coordinates[coordinates.length - 1]);
        if (angle <= 90 && angle >= min_angle) {
            $('.sub-level2').hide();
            $('#sub_cat_' + cat + ', #sub_cat_' + cat + ' .sub-level2').show();
            $('#sub_cat_' + cat).addClass('sub_active');
        } else {
            nav_timeout = setTimeout(function () {
                $('.sub-level2').hide();
                $('#sub_cat_' + cat + ', #sub_cat_' + cat + ' .sub-level2').show();
                $('#sub_cat_' + cat).addClass('sub_active');
            }, 250)
        }
    }, function () {
        window.clearTimeout(nav_timeout);
    });
    $('.wrap-sub, .sub-level2').hover(function (e) {
        $(this).show();
    }, function () {});
    $('.par_cat').mouseenter(flyout);
    $('#flyout').mouseleave(hide_all);
    var tm;
    $('#big-daddy').hover(function () {
        if ($(this).hasClass('active')) {
            return false;
        }
        $('.viewall-item').addClass('active');
        $('#flyout').addClass('active');
    }, function () {
        if ($(this).hasClass('active')) {
            return false;
        }
        $('.viewall-item').removeClass('active');
        $('#flyout').removeClass('active');
    });
});

function add_coordinates(coordinates_value) {
    coordinates.push(coordinates_value);
    if (coordinates.length > mousestep) coordinates.shift();
}

function get_angel(coordinates1, coordinates2) {
    var dx = coordinates1.x - coordinates2.x;
    var dy = coordinates1.y - coordinates2.y;
    return Math.acos(dx / Math.sqrt(dx * dx + dy * dy)) * (180 / Math.PI);
}

$(document).ready(function () {
    var cart_tm;
    $('.your-cart').hover(function () {
        window.clearTimeout(cart_tm);
        $(this).find('a:first').addClass('active');
        $('.sub-drop-cart').slideDown(300);
    }, function () {
        cart_tm = setTimeout(function () {
            $('.drop-cart a:first').removeClass('active');
            $('.sub-drop-cart').slideUp(300);
        }, 400);
    });
});

jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend(jQuery.easing, {
    def: 'easeOutQuad',
    swing: function (x, t, b, c, d) {
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeInQuad: function (x, t, b, c, d) {
        return c * (t /= d) * t + b;
    },
    easeOutQuad: function (x, t, b, c, d) {
        return -c * (t /= d) * (t - 2) + b;
    },
    easeInOutQuad: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t + b;
        return -c / 2 * ((--t) * (t - 2) - 1) + b;
    },
    easeInCubic: function (x, t, b, c, d) {
        return c * (t /= d) * t * t + b;
    },
    easeOutCubic: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t + 1) + b;
    },
    easeInOutCubic: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t + 2) + b;
    },
    easeInQuart: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t + b;
    },
    easeOutQuart: function (x, t, b, c, d) {
        return -c * ((t = t / d - 1) * t * t * t - 1) + b;
    },
    easeInOutQuart: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
        return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
    },
    easeInQuint: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t * t + b;
    },
    easeOutQuint: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
    },
    easeInOutQuint: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
    },
    easeInSine: function (x, t, b, c, d) {
        return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
    },
    easeOutSine: function (x, t, b, c, d) {
        return c * Math.sin(t / d * (Math.PI / 2)) + b;
    },
    easeInOutSine: function (x, t, b, c, d) {
        return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
    },
    easeInExpo: function (x, t, b, c, d) {
        return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
    },
    easeInOutExpo: function (x, t, b, c, d) {
        if (t == 0) return b;
        if (t == d) return b + c;
        if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
        return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
    },
    easeInCirc: function (x, t, b, c, d) {
        return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
    },
    easeOutCirc: function (x, t, b, c, d) {
        return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
    },
    easeInOutCirc: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
        return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
    },
    easeInElastic: function (x, t, b, c, d) {
        var s = 1.70158;
        var p = 0;
        var a = c;
        if (t == 0) return b;
        if ((t /= d) == 1) return b + c;
        if (!p) p = d * .3;
        if (a < Math.abs(c)) {
            a = c;
            var s = p / 4;
        } else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
    },
    easeOutElastic: function (x, t, b, c, d) {
        var s = 1.70158;
        var p = 0;
        var a = c;
        if (t == 0) return b;
        if ((t /= d) == 1) return b + c;
        if (!p) p = d * .3;
        if (a < Math.abs(c)) {
            a = c;
            var s = p / 4;
        } else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
    },
    easeInOutElastic: function (x, t, b, c, d) {
        var s = 1.70158;
        var p = 0;
        var a = c;
        if (t == 0) return b;
        if ((t /= d / 2) == 2) return b + c;
        if (!p) p = d * (.3 * 1.5);
        if (a < Math.abs(c)) {
            a = c;
            var s = p / 4;
        } else var s = p / (2 * Math.PI) * Math.asin(c / a);
        if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
        return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
    },
    easeInBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * (t /= d) * t * ((s + 1) * t - s) + b;
    },
    easeOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
    },
    easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
        return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
    },
    easeInBounce: function (x, t, b, c, d) {
        return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b;
    },
    easeOutBounce: function (x, t, b, c, d) {
        if ((t /= d) < (1 / 2.75)) {
            return c * (7.5625 * t * t) + b;
        } else if (t < (2 / 2.75)) {
            return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
        } else if (t < (2.5 / 2.75)) {
            return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
        } else {
            return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
        }
    },
    easeInOutBounce: function (x, t, b, c, d) {
        if (t < d / 2) return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b;
        return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b;
    }
});

(function ($) {
    var ct;
    var p = this;
    var rotations_count = 0;
    var callback = function () {};
    var bg_mask;
    var bg_mask_2;
    var slides = [];
    var min_time = 500;
    var max_time = 3000;
    var direction = 'horizontal';
    var easing = 'easeInOutExpo';
    var easing_in = '';
    var easing_out = '';
    var keyboard_navigate = true;
    var prev_next_nav = true;
    var center_prev_next_nav = true;
    var prev_next_nav_margin = 50;
    var slides_nav = true;
    var random = true;
    var autoswitch = false;
    var autoswitch_interval = 5000;
    var autoswitch_interval_func = null;
    var current_index = 0;
    var total_slides = 0;
    var timeout;
    var horizontal_direction = '';
    var vertical_direction = '';
    var base_zindex = 1000;
    var busy = false;
    var _next_a, _prev_a;
    var slides_nav_el;

    function sliderPrepare(el, options) {
        if (typeof ct == 'undefined') {
            ct = $(el);
            ct.css({
                position: 'relative'
            });
            if (typeof options == 'object') {
                if (typeof options.direction == 'string') {
                    if (options.direction.toLowerCase() == 'vertical') {
                        direction = 'vertical';
                    } else {
                        direction = 'horizontal';
                    }
                }
                if (typeof options.random != 'undefined') {
                    random = options.random;
                }
                if (typeof options.minTime != 'undefined') {
                    min_time = options.minTime;
                }
                if (typeof options.maxTime != 'undefined') {
                    max_time = options.maxTime;
                }
                if (typeof options.easing == 'string') {
                    easing = options.easing;
                }
                if (typeof options.easingIn == 'string') {
                    easing_in = options.easingIn;
                }
                if (typeof options.easingOut == 'string') {
                    easing_out = options.easingOut;
                }
                if (typeof options.keyboardNavigate != 'undefined') {
                    keyboard_navigate = options.keyboardNavigate ? true : false;
                }
                if (typeof options.prevNextNav != 'undefined') {
                    prev_next_nav = options.prevNextNav;
                }
                if (typeof options.centerPrevNextNav != 'undefined') {
                    center_prev_next_nav = true;

                    prev_next_nav_margin = parseInt(options.centerPrevNextNav, 10);
                }
                if (typeof options.slidesNav != 'undefined') {
                    slides_nav = options.slidesNav;
                }
                if (typeof options.autoswitch == 'number' && options.autoswitch > 0) {
                    autoswitch = true;
                    autoswitch_interval = options.autoswitch;
                    _autoSwitch("on");
                }
            } else {
                options = {};
            }
            ct.children().each(function (i) {
                var slide = $(this);
                var slide_elements = slide.find('*');
                slide.hide().css({
                    zIndex: base_zindex + 10,
                    position: 'relative'
                });
                slide.height = slide.outerHeight() > slide.height() ? slide.outerHeight() : slide.height();
                slide.width = slide.outerWidth();
                slide.background = false;
                var sbg = "";
                var _bg_color = slide.css("background-color");
                var _bg_image = slide.css("background-image");
                var _bg_repeat = slide.css("background-repeat");
                var _bg_position = slide.css("background-position");
                var _bg_property = _bg_color + ' ' + (_bg_image == 'none' ? '' : _bg_image) + ' ' + _bg_position + ' ' + _bg_repeat;
                if (_bg_image != 'none' || _bg_color) {
                    sbg = _bg_property;
                    slide.css("background", "none");
                }
                if (sbg || slide.attr("data-background")) {
                    slide.background = sbg;
                    if (slide.attr("data-background")) {
                        slide.background = slide.attr("data-background");
                    }
                    var img_url = [];
                    img_url = slide.background.match(/url\((.*?)\)/);
                    if (img_url && img_url.length > 0) {
                        var img = new Image();
                        img.src = img_url[1];
                    }
                }
                slide.elements = [];
                slide_elements.each(function () {
                    var $this = $(this);
                    var def_left = parseInt($this.css("left"), 10);
                    var def_top = parseInt($this.css("top"), 10);
                    $this.def_left = 0;
                    $this.def_top = 0;
                    if (def_left) {
                        $this.def_left = def_left;
                    }
                    if (def_top) {
                        $this.def_top = def_top;
                    }
                    if ($this.css('position') != 'absolute') {
                        $this.css({
                            position: 'relative'
                        });
                    }
                    $this.css({
                        zIndex: base_zindex + 10
                    });
                    if ($this.get(0).tagName != "BR") {
                        slide.elements.push($this);
                    }
                });
                slide.index = parseInt(i, 10);
                slides.push(slide);
                if (i === 0) {
                    slide.show();
                    ct.height(slide.height).css({
                        overflow: 'hidden'
                    });
                    bg_mask = $('<div id="asyncslider_background_mask"></div>');
                    bg_mask_2 = $('<div id="asyncslider_background_mask_2"></div>');
                    slide.before(bg_mask);
                    slide.before(bg_mask_2);
                    bg_mask.css({
                        position: 'absolute',
                        top: 0,
                        left: 0,
                        zIndex: base_zindex + 1,
                        padding: 0,
                        margin: 0,
                        width: ct.outerWidth(),
                        height: ct.outerHeight()
                    });
                    bg_mask_2.css({
                        position: 'absolute',
                        top: 0,
                        left: 0,
                        zIndex: base_zindex + 2,
                        padding: 0,
                        margin: 0,
                        width: ct.outerWidth(),
                        height: ct.outerHeight()
                    });
                    $(window).resize(function () {
                        bg_mask.width(ct.outerWidth());
                        bg_mask_2.width(ct.outerWidth());
                    });
                    if (slide.background) {
                        bg_mask.css("background", slide.background);
                    }
                }
            });
            total_slides = slides.length;
            if (typeof options != 'undefined' && typeof options.firstSlide != 'undefined') {
                var fs_index = options.firstSlide - 1;
                if (fs_index >= 0 && fs_index < total_slides) {
                    var tmp_min_time = min_time,
                        tmp_max_time = max_time,
                        tmp_callback = callback;
                    min_time = max_time = 0;
                    callback = function () {};
                    current_index = fs_index;
                    switchSlide(current_index, 0);
                    min_time = tmp_min_time;
                    max_time = tmp_max_time;
                    callback = tmp_callback;
                }
            }
            if (ct.children().length < 2) {
                return;
            }
            $(window).keydown(function (e) {
                if (keyboard_navigate) {
                    switch (e.keyCode) {
                    case 37:
                        prevSlide();
                        break;
                    case 39:
                        nextSlide();
                        break;
                    }
                }
            });
            if (prev_next_nav && total_slides > 1) {
                var next_prev_nav_el = $('<ul id="asyncslider_next_prev_nav" />');
                next_prev_nav_el.css({
                    zIndex: base_zindex + 100
                });
                var prev_li = $('<li class="prev" />');
                var next_li = $('<li class="next" />');
                var prev_a = $('<a href="#"></a>');
                var next_a = $('<a href="#"></a>');
                next_prev_nav_el.append(prev_li);
                next_prev_nav_el.append(next_li);
                prev_li.append(prev_a);
                next_li.append(next_a);
                prev_li.click(function (ev) {
                    ev.preventDefault();
                    prevSlide();
                });
                next_li.click(function (ev) {
                    ev.preventDefault();
                    nextSlide();
                });
                if (typeof prev_next_nav == 'object') {
                    prev_next_nav.append(next_prev_nav_el);
                } else {
                    ct.append(next_prev_nav_el);
                    if (center_prev_next_nav) {
                        var margin_h = prev_next_nav_margin;
                        var current_slide = getSlide(current_index);
                        next_prev_nav_el.css({
                            position: 'absolute',
                            left: "50%",
                            margin: 0,
                            padding: 0,
                            listStyle: 'none',
                            marginLeft: -parseInt(current_slide.outerWidth() / 2, 10),
                            top: 0
                        });
                        next_prev_nav_el.find('*').css({
                            margin: 0,
                            padding: 0
                        });
                        var next = next_prev_nav_el.find('.next');
                        var prev = next_prev_nav_el.find('.prev');
                        _next_a = next.children();
                        _prev_a = prev.children().css({
                            left: -prev_a.width() - margin_h
                        });
                        prev.add(next).css({
                            position: 'relative'
                        });
                        prev.width(_prev_a.width());
                        next.width(_next_a.width());
                        _next_a.add(_prev_a).css({
                            position: 'absolute'
                        });
                        _next_a.css({
                            left: current_slide.outerWidth() + margin_h,
                            top: parseInt(current_slide.outerHeight() / 2 - _prev_a.outerHeight() / 2, 10)
                        });
                        _prev_a.css({
                            top: parseInt(current_slide.outerHeight() / 2 - _prev_a.outerHeight() / 2, 10)
                        });
                    }
                }
            }
            if (slides_nav) {
                slides_nav_el = $('<ul id="asyncslider_slides_nav" />');
                slides_nav_el.css({
                    zIndex: base_zindex + 100
                });
                for (var i = 0; i < slides.length; i++) {
                    var slide = slides[i];
                    var slide_button_li = $('<li id="asyncslider_slide_' + (parseInt(i, 10) + 1) + '" />');
                    var slide_button_a = $('<a href="#" rel="' + (i) + '">' + (parseInt(i, 10) + 1) + '</a>');
                    if (i === 0 && typeof options.firstSlide == 'undefined') {
                        slide_button_li.addClass('active');
                    } else if (typeof options.firstSlide != 'undefined' && i == parseInt(options.firstSlide, 10) - 1) {
                        slide_button_li.addClass('active');
                    }
                    slides_nav_el.append(slide_button_li);
                    slide_button_li.append(slide_button_a);
                    index = parseInt(i, 10);
                    var btn_click_a = slide_button_a.click(function (ev) {
                        ev.preventDefault();
                        if (busy) {
                            return false;
                        }
                        slides_nav_el.find('li').removeClass('active');
                        $(this).parent().addClass('active');
                        var i = parseInt($(this).attr("rel"), 10);
                        var old_index = current_index;
                        current_index = i;
                        switchSlide(current_index, old_index);
                    });
                }
                if (typeof slides_nav == 'object') {
                    slides_nav.append(slides_nav_el);
                } else {
                    ct.append(slides_nav_el);
                }
            }
        }
    }

    function setIndex(index) {
        if (index >= 0 && index < total_slides) {
            current_index = index;
        }
    }

    function getSlide(index) {
        if (index >= 0 && index < total_slides) {
            return slides[index];
        }
        return null;
    }

    function nextSlide(_direction) {
        if (busy) {
            return false;
        }
        var old_index = current_index;
        current_index++;
        current_index = current_index % total_slides;
        horizontal_direction = 'left';
        vertical_direction = 'bottom';
        if (_direction) {
            horizontal_direction = _direction == 'right' ? 'right' : 'left';
        }
        if (_direction) {
            vertical_direction = _direction == 'bottom' ? 'top' : 'bottom';
        }
        switchSlide(current_index, old_index);
    }

    function prevSlide(_direction) {
        if (busy) {
            return false;
        }
        var old_index = current_index;
        current_index--;
        current_index = current_index < 0 ? (total_slides - 1) : current_index;
        horizontal_direction = 'right';
        vertical_direction = 'top';
        if (_direction) {
            horizontal_direction = _direction == 'left' ? 'left' : 'right';
        }
        if (_direction) {
            vertical_direction = _direction == 'top' ? 'bottom' : 'top';
        }
        switchSlide(current_index, old_index);
    }

    function switchSlide(_in, _out) {
        var current_slide = getSlide(_out);
        var next_slide = getSlide(_in);
        if ((!current_slide || !next_slide) || _in == _out) {
            return false;
        }
        if (busy) {
            return false;
        }
        busy = true;
        var half_m = parseInt((max_time + min_time) / 2, 10);
        max_time = min_time > max_time ? min_time : max_time;
        min_time = min_time > max_time ? max_time : min_time;
        if (next_slide.background) {
            if (!current_slide.background) {
                bg_mask.css({
                    background: next_slide.background
                }).hide().fadeTo(half_m, 1);
            } else {
                if (rotations_count == 0) {
                    bg_mask.css({
                        background: current_slide.background
                    });
                    bg_mask_2.hide().css({
                        background: next_slide.background
                    }).stop().fadeTo(half_m, 1);
                } else {
                    bg_mask.css({
                        background: next_slide.background
                    }).show();
                    bg_mask_2.stop().fadeTo(half_m, 0, function () {
                        bg_mask.hide();
                        bg_mask_2.css({
                            background: next_slide.background
                        }).fadeTo(0, 1);
                    });
                }
            }
        } else {
            bg_mask_2.stop().fadeTo(half_m, 0);
            bg_mask.stop().fadeTo(half_m, 0);
        }
        if (center_prev_next_nav && _next_a && _prev_a) {
            _next_a.stop().animate({
                top: parseInt(next_slide.outerHeight() / 2 - _next_a.outerHeight() / 2, 10)
            }, half_m);
            _prev_a.stop().animate({
                top: parseInt(next_slide.outerHeight() / 2 - _prev_a.outerHeight() / 2, 10)
            }, half_m);
        }
        bg_mask.stop().animate({
            height: next_slide.height
        }, half_m);
        bg_mask_2.height(next_slide.height);
        if (slides_nav_el) {
            slides_nav_el.find('li').removeClass('active').filter(':nth-child(' + (next_slide.index + 1) + ')').addClass('active');
        }
        var turn = 1,
            i, el, time_seq, time_seq_step, def_left, def_top, animation_length, move_top, move_left;
        if (direction == 'horizontal') {
            var win = $(window);
            var win_ct_gap_size = win.width() - next_slide.width;
            ct.css({
                overflow: "hidden"
            }).stop().animate({
                height: next_slide.height
            }, half_m);
            var move_left_1 = parseInt(current_slide.width / 2 + win_ct_gap_size / 2, 10);
            if (_in > _out) {
                move_top = current_slide.height;
                if (move_top < next_slide.height) {
                    move_top = next_slide.height - (next_slide.height - current_slide.height);
                }
                current_slide.css({
                    position: 'relative',
                    zIndex: base_zindex + 3
                });
                next_slide.css({
                    position: 'relative',
                    zIndex: base_zindex + 4,
                    top: -move_top
                }).show();
                turn = 1;
            } else {
                move_top = current_slide.height;
                if (move_top < next_slide.height) {
                    move_top = next_slide.height;
                } else {
                    move_top -= (current_slide.height - next_slide.height);
                }
                current_slide.css({
                    position: 'relative',
                    zIndex: base_zindex + 3,
                    top: -move_top
                });
                next_slide.css({
                    position: 'relative',
                    zIndex: base_zindex + 4
                }).show();
                turn = -1;
            }
            if (horizontal_direction) {
                if (horizontal_direction == 'right') {
                    turn = -1;
                } else {
                    turn = 1;
                }
            }
            if (!easing_in) {
                easing_in = easing;
            }
            if (!easing_out) {
                easing_out = easing;
            }
            time_seq = min_time;
            time_seq_step = parseInt((max_time - min_time) / current_slide.elements.length, 10);
            move_left = current_slide.width + win_ct_gap_size;
            for (i = 0; i < current_slide.elements.length; i++) {
                el = current_slide.elements[i];
                def_left = el.def_left;
                def_top = el.def_top;
                animation_length = randomFromTo(min_time, max_time);
                move_left_1 = move_left;
                if (!random) {
                    time_seq += time_seq_step;
                    animation_length = time_seq;
                }
                el.stop().animate({
                    left: -turn * move_left_1 + def_left,
                    top: def_top + 0
                }, animation_length, easing_in);
            }
            time_seq = min_time;
            time_seq_step = parseInt((max_time - min_time) / next_slide.elements.length, 10);
            move_left = next_slide.width + win_ct_gap_size;
            var next_slide_total_elements = next_slide.elements.length;
            for (i = 0; i < next_slide.elements.length; i++) {
                el = next_slide.elements[i];
                def_left = el.def_left;
                def_top = el.def_top;
                animation_length = randomFromTo(min_time, max_time);
                move_left_1 = move_left + randomFromTo(0, el.outerWidth());
                if (!random) {
                    time_seq += time_seq_step;
                    animation_length = time_seq;
                }
                var _index = parseInt(i, 10);
                el.css({
                    left: turn * move_left_1 + def_left,
                    top: def_top + 0
                }).stop().animate({
                    left: 0 + def_left
                }, animation_length, easing_out);
            }
        } else {
            ct.css({
                overflow: "hidden"
            }).stop().animate({
                height: next_slide.height
            }, half_m);
            var move_top_1 = ct.height();
            if (_in > _out) {
                current_slide.css({
                    position: 'relative',
                    zIndex: base_zindex + 3
                });
                next_slide.css({
                    position: 'relative',
                    zIndex: base_zindex + 4,
                    top: -current_slide.height
                }).show();
                turn = 1;
            } else {
                current_slide.css({
                    position: 'relative',
                    zIndex: base_zindex + 3,
                    top: -current_slide.height
                });
                next_slide.css({
                    position: 'relative',
                    zIndex: base_zindex + 4
                }).show();
                turn = -1;
            }
            if (vertical_direction) {
                if (vertical_direction == 'top') {
                    turn = -1;
                } else {
                    turn = 1;
                }
            }
            if (!easing_in) {
                easing_in = easing;
            }
            if (!easing_out) {
                easing_out = easing;
            }
            current_slide.animate({
                top: -turn * move_top_1
            }, half_m);
            time_seq = min_time;
            time_seq_step = parseInt((max_time - min_time) / current_slide.elements.length, 10);
            for (i = 0; i < current_slide.elements.length; i++) {
                el = current_slide.elements[i];
                def_left = el.def_left;
                def_top = el.def_top;
                animation_length = randomFromTo(min_time, max_time);
                move_top = move_top_1;
                if (!random) {
                    time_seq += time_seq_step;
                    animation_length = time_seq;
                }
                el.stop().animate({
                    top: -turn * move_top + def_top
                }, animation_length, easing_in);
            }
            time_seq = min_time;
            time_seq_step = parseInt((max_time - min_time) / next_slide.elements.length, 10);
            for (i = 0; i < next_slide.elements.length; i++) {
                el = next_slide.elements[i];
                def_left = el.def_left;
                def_top = el.def_top;
                animation_length = randomFromTo(min_time, max_time);
                move_top = move_top_1;
                if (!random) {
                    time_seq += time_seq_step;
                    animation_length = time_seq;
                }
                el.css({
                    top: turn * move_top,
                    left: 0 + def_left
                }).stop().animate({
                    top: 0 + def_top
                }, animation_length, easing_out);
            }
        }
        timeout = window.setTimeout(function () {
            current_slide.css({
                position: 'relative',
                top: 0,
                left: 0
            }).hide();
            next_slide.css({
                position: 'relative',
                top: 0,
                left: 0
            });
            for (i = 0; i < current_slide.elements.length; i++) {
                el = current_slide.elements[i];
                def_left = el.def_left;
                def_top = el.def_top;
                el.css({
                    left: def_left
                });
                el.css({
                    top: def_top
                });
            }
            for (i = 0; i < next_slide.elements.length; i++) {
                el = next_slide.elements[i];
                def_left = el.def_left;
                def_top = el.def_top;
                el.css({
                    left: def_left
                });
                el.css({
                    top: def_top
                });
            }
            horizontal_direction = '';
            callback(next_slide.index + 1);
            window.clearTimeout(timeout);
            timeout = null;
            busy = false;
            if (typeof autoswitch_interval_func != 'undefined') {
                if (autoswitch) {
                    window.clearTimeout(autoswitch_interval_func);
                    autoswitch_interval_func = null;
                    _autoSwitch("on");
                }
            }
            rotations_count++;
        }, max_time);
        return true;
    }

    function randomFromTo(from, to) {
        return Math.floor(Math.random() * (to - from + 1) + from);
    }

    function setOption(_var, _val) {
        switch (_var.toLowerCase()) {
        case "direction":
            if (_val == "vertical") {
                direction = 'vertical';
            } else {
                direction = 'horizontal';
            }
            break;
        case "callback":
            if (typeof _val == 'function') {
                callback = _val;
            }
            break;
        case "minTime":
            min_time = parseInt(_val, 10);
            break;
        case "maxTime":
            max_time = parseInt(_val, 10);

            break;
        case "easing":
            easing_in = '';
            easing_out = '';
            easing = _val;
            break;
        case "easingin":
            easing_in = _val;
            break;
        case "easingout":
            easing_out = _val;
            break;
        case "keyboardnavigate":
            keyboard_navigate = _val ? true : false;
            break;
        case "random":
            random = _val ? true : false;
            break;
        case "autoswitch":
            if (typeof _val == 'number' && _val > 0) {
                _autoSwitch("update_interval", _val);
            } else if (typeof _val == 'string' && (_val.toLowerCase() == 'play' || _val.toLowerCase() == 'on' || _val.toLowerCase() == 'off' || _val.toLowerCase() == 'pause')) {
                _autoSwitch(_val.toLowerCase());
            } else if (typeof _val == 'string' && _val.toLowerCase() == 'pause') {
                _autoSwitch("pause");
            }
            break;
        }
    }

    function _autoSwitch(type, new_value) {
        switch (type) {
        case "off":
            autoswitch = false;
            if (typeof autoswitch_interval_func != 'undefined') {
                window.clearInterval(autoswitch_interval_func);
                autoswitch_interval_func = null;
            }
            break;
        case "on":
            ct.on('mouseenter', function () {
                autoswitch = false;
            }).on('mouseleave', function () {
                _autoSwitch("update_interval", autoswitch_interval);
            });
            _autoSwitch("update_interval", autoswitch_interval);
            break;
        case "update_interval":
            autoswitch = true;
            autoswitch_interval = new_value;
            if (typeof autoswitch_interval_func != 'undefined') {
                window.clearInterval(autoswitch_interval_func);
                autoswitch_interval_func = null;
            }
            autoswitch_interval_func = setInterval(function () {
                if (autoswitch) {
                    nextSlide();
                }
            }, autoswitch_interval);
            break;
        case "play":
            autoswitch = true;
            if (typeof autoswitch_interval_func == 'undefined') {
                _autoSwitch("on");
            }
            break;
        case "pause":
            autoswitch = false;
            break;
        }
    }
    $.fn.extend({
        asyncSlider: function (options, _var, _val) {
            if (typeof options == 'string') {
                switch (options.toLowerCase()) {
                case "movetoslide":
                    var move_to_slide = parseInt(_var, 10);
                    if (move_to_slide > 0 && move_to_slide <= total_slides) {
                        var old_index = current_index;
                        current_index = move_to_slide - 1;
                        if (_val) {
                            horizontal_direction = _val == 'right' ? 'right' : 'left';
                        }
                        if (_val) {
                            vertical_direction = _val == 'bottom' ? 'top' : 'bottom';
                        }
                        switchSlide(current_index, old_index);
                    }
                    break;
                case "set":
                    setOption(_var, _val);
                    break;
                case "next":
                    nextSlide(_var);
                    break;
                case "prev":
                    prevSlide(_var);
                    break;
                }
            }
            sliderPrepare(this, options);
            if (typeof _var == 'function') {
                callback = _var;
            }
        }
    });
})(jQuery);

jQuery(document).ready(function () {
    var asyncslider = $(".slider_container");
    asyncslider.asyncSlider({
        direction: 'horizontal',
        minTime: 500,
        maxTime: 100,
        random: true,
        autoswitch: 5000,
        slidesNav: true,
        slidesNav: $(".slider_buttons_env")
    });
});

(function (g) {
    var q = {
        vertical: !1,
        rtl: !1,
        start: 1,
        offset: 1,
        size: null,
        scroll: 3,
        visible: null,
        animation: "normal",
        easing: "swing",
        auto: 0,
        wrap: null,
        initCallback: null,
        setupCallback: null,
        reloadCallback: null,
        itemLoadCallback: null,
        itemFirstInCallback: null,
        itemFirstOutCallback: null,
        itemLastInCallback: null,
        itemLastOutCallback: null,
        itemVisibleInCallback: null,
        itemVisibleOutCallback: null,
        animationStepCallback: null,
        buttonNextHTML: "<div></div>",
        buttonPrevHTML: "<div></div>",
        buttonNextEvent: "click",
        buttonPrevEvent: "click",
        buttonNextCallback: null,
        buttonPrevCallback: null,
        itemFallbackDimension: null
    },
        m = !1;
    g(window).bind("load.jcarousel", function () {
        m = !0
    });
    g.jcarousel = function (a, c) {
        this.options = g.extend({}, q, c || {});
        this.autoStopped = this.locked = !1;
        this.buttonPrevState = this.buttonNextState = this.buttonPrev = this.buttonNext = this.list = this.clip = this.container = null;
        if (!c || c.rtl === void 0) this.options.rtl = (g(a).attr("dir") || g("html").attr("dir") || "").toLowerCase() == "rtl";
        this.wh = !this.options.vertical ? "width" : "height";
        this.lt = !this.options.vertical ? this.options.rtl ? "right" : "left" : "top";
        for (var b = "", d = a.className.split(" "), f = 0; f < d.length; f++) if (d[f].indexOf("jcarousel-skin") != -1) {
            g(a).removeClass(d[f]);
            b = d[f];
            break
        }
        a.nodeName.toUpperCase() == "UL" || a.nodeName.toUpperCase() == "OL" ? (this.list = g(a), this.clip = this.list.parents(".jcarousel-clip"), this.container = this.list.parents(".jcarousel-container")) : (this.container = g(a), this.list = this.container.find("ul,ol").eq(0), this.clip = this.container.find(".jcarousel-clip"));
        if (this.clip.size() === 0) this.clip = this.list.wrap("<div></div>").parent();
        if (this.container.size() === 0) this.container = this.clip.wrap("<div></div>").parent();
        b !== "" && this.container.parent()[0].className.indexOf("jcarousel-skin") == -1 && this.container.wrap('<div class=" ' + b + '"></div>');
        this.buttonPrev = g(".jcarousel-prev", this.container);
        if (this.buttonPrev.size() === 0 && this.options.buttonPrevHTML !== null) this.buttonPrev = g(this.options.buttonPrevHTML).appendTo(this.container);
        this.buttonPrev.addClass(this.className("jcarousel-prev"));
        this.buttonNext = g(".jcarousel-next", this.container);
        if (this.buttonNext.size() === 0 && this.options.buttonNextHTML !== null) this.buttonNext = g(this.options.buttonNextHTML).appendTo(this.container);
        this.buttonNext.addClass(this.className("jcarousel-next"));
        this.clip.addClass(this.className("jcarousel-clip")).css({
            position: "relative"
        });
        this.list.addClass(this.className("jcarousel-list")).css({
            overflow: "hidden",
            position: "relative",
            top: 0,
            margin: 0,
            padding: 0
        }).css(this.options.rtl ? "right" : "left", 0);
        this.container.addClass(this.className("jcarousel-container")).css({
            position: "relative"
        });
        !this.options.vertical && this.options.rtl && this.container.addClass("jcarousel-direction-rtl").attr("dir", "rtl");
        var j = this.options.visible !== null ? Math.ceil(this.clipping() / this.options.visible) : null,
            b = this.list.children("li"),
            e = this;
        if (b.size() > 0) {
            var h = 0,
                i = this.options.offset;
            b.each(function () {
                e.format(this, i++);
                h += e.dimension(this, j)
            });
            this.list.css(this.wh, h + 100 + "px");
            if (!c || c.size === void 0) this.options.size = b.size()
        }
        this.container.css("display", "block");
        this.buttonNext.css("display", "block");
        this.buttonPrev.css("display", "block");
        this.funcNext = function () {
            e.next()
        };
        this.funcPrev = function () {
            e.prev()
        };
        this.funcResize = function () {
            e.resizeTimer && clearTimeout(e.resizeTimer);
            e.resizeTimer = setTimeout(function () {
                e.reload()
            }, 100)
        };
        this.options.initCallback !== null && this.options.initCallback(this, "init");
        !m && g.browser.safari ? (this.buttons(!1, !1), g(window).bind("load.jcarousel", function () {
            e.setup()
        })) : this.setup()
    };
    var f = g.jcarousel;
    f.fn = f.prototype = {
        jcarousel: "0.2.8"
    };
    f.fn.extend = f.extend = g.extend;
    f.fn.extend({
        setup: function () {
            this.prevLast = this.prevFirst = this.last = this.first = null;
            this.animating = !1;
            this.tail = this.resizeTimer = this.timer = null;
            this.inTail = !1;
            if (!this.locked) {
                this.list.css(this.lt, this.pos(this.options.offset) + "px");
                var a = this.pos(this.options.start, !0);
                this.prevFirst = this.prevLast = null;
                this.animate(a, !1);
                g(window).unbind("resize.jcarousel", this.funcResize).bind("resize.jcarousel", this.funcResize);
                this.options.setupCallback !== null && this.options.setupCallback(this)
            }
        },
        reset: function () {
            this.list.empty();
            this.list.css(this.lt, "0px");
            this.list.css(this.wh, "10px");
            this.options.initCallback !== null && this.options.initCallback(this, "reset");
            this.setup()
        },
        reload: function () {
            this.tail !== null && this.inTail && this.list.css(this.lt, f.intval(this.list.css(this.lt)) + this.tail);
            this.tail = null;
            this.inTail = !1;
            this.options.reloadCallback !== null && this.options.reloadCallback(this);
            if (this.options.visible !== null) {
                var a = this,
                    c = Math.ceil(this.clipping() / this.options.visible),
                    b = 0,
                    d = 0;
                this.list.children("li").each(function (f) {
                    b += a.dimension(this, c);
                    f + 1 < a.first && (d = b)
                });
                this.list.css(this.wh, b + "px");
                this.list.css(this.lt, -d + "px")
            }
            this.scroll(this.first, !1)
        },
        lock: function () {
            this.locked = !0;
            this.buttons()
        },
        unlock: function () {
            this.locked = !1;
            this.buttons()
        },
        size: function (a) {
            if (a !== void 0) this.options.size = a, this.locked || this.buttons();
            return this.options.size
        },
        has: function (a, c) {
            if (c === void 0 || !c) c = a;
            if (this.options.size !== null && c > this.options.size) c = this.options.size;
            for (var b = a; b <= c; b++) {
                var d = this.get(b);
                if (!d.length || d.hasClass("jcarousel-item-placeholder")) return !1
            }
            return !0
        },
        get: function (a) {
            return g(">.jcarousel-item-" + a, this.list)
        },
        add: function (a, c) {
            var b = this.get(a),
                d = 0,
                p = g(c);
            if (b.length === 0) for (var j, e = f.intval(a), b = this.create(a);;) {
                if (j = this.get(--e), e <= 0 || j.length) {
                    e <= 0 ? this.list.prepend(b) : j.after(b);
                    break
                }
            } else d = this.dimension(b);
            p.get(0).nodeName.toUpperCase() == "LI" ? (b.replaceWith(p), b = p) : b.empty().append(c);
            this.format(b.removeClass(this.className("jcarousel-item-placeholder")), a);
            p = this.options.visible !== null ? Math.ceil(this.clipping() / this.options.visible) : null;
            d = this.dimension(b, p) - d;
            a > 0 && a < this.first && this.list.css(this.lt, f.intval(this.list.css(this.lt)) - d + "px");
            this.list.css(this.wh, f.intval(this.list.css(this.wh)) + d + "px");
            return b
        },
        remove: function (a) {
            var c = this.get(a);
            if (c.length && !(a >= this.first && a <= this.last)) {
                var b = this.dimension(c);
                a < this.first && this.list.css(this.lt, f.intval(this.list.css(this.lt)) + b + "px");
                c.remove();
                this.list.css(this.wh, f.intval(this.list.css(this.wh)) - b + "px")
            }
        },
        next: function () {
            this.tail !== null && !this.inTail ? this.scrollTail(!1) : this.scroll((this.options.wrap == "both" || this.options.wrap == "last") && this.options.size !== null && this.last == this.options.size ? 1 : this.first + this.options.scroll)
        },
        prev: function () {
            this.tail !== null && this.inTail ? this.scrollTail(!0) : this.scroll((this.options.wrap == "both" || this.options.wrap == "first") && this.options.size !== null && this.first == 1 ? this.options.size : this.first - this.options.scroll)
        },
        scrollTail: function (a) {
            if (!this.locked && !this.animating && this.tail) {
                this.pauseAuto();
                var c = f.intval(this.list.css(this.lt)),
                    c = !a ? c - this.tail : c + this.tail;
                this.inTail = !a;
                this.prevFirst = this.first;
                this.prevLast = this.last;
                this.animate(c)
            }
        },
        scroll: function (a, c) {
            !this.locked && !this.animating && (this.pauseAuto(), this.animate(this.pos(a), c))
        },
        pos: function (a, c) {
            var b = f.intval(this.list.css(this.lt));
            if (this.locked || this.animating) return b;
            this.options.wrap != "circular" && (a = a < 1 ? 1 : this.options.size && a > this.options.size ? this.options.size : a);
            for (var d = this.first > a, g = this.options.wrap != "circular" && this.first <= 1 ? 1 : this.first, j = d ? this.get(g) : this.get(this.last), e = d ? g : g - 1, h = null, i = 0, k = !1, l = 0; d ? --e >= a : ++e < a;) {
                h = this.get(e);
                k = !h.length;
                if (h.length === 0 && (h = this.create(e).addClass(this.className("jcarousel-item-placeholder")), j[d ? "before" : "after"](h), this.first !== null && this.options.wrap == "circular" && this.options.size !== null && (e <= 0 || e > this.options.size))) j = this.get(this.index(e)), j.length && (h = this.add(e, j.clone(!0)));
                j = h;
                l = this.dimension(h);
                k && (i += l);
                if (this.first !== null && (this.options.wrap == "circular" || e >= 1 && (this.options.size === null || e <= this.options.size))) b = d ? b + l : b - l
            }
            for (var g = this.clipping(), m = [], o = 0, n = 0, j = this.get(a - 1), e = a; ++o;) {
                h = this.get(e);
                k = !h.length;
                if (h.length === 0) {
                    h = this.create(e).addClass(this.className("jcarousel-item-placeholder"));
                    if (j.length === 0) this.list.prepend(h);
                    else j[d ? "before" : "after"](h);
                    if (this.first !== null && this.options.wrap == "circular" && this.options.size !== null && (e <= 0 || e > this.options.size)) j = this.get(this.index(e)), j.length && (h = this.add(e, j.clone(!0)))
                }
                j = h;
                l = this.dimension(h);
                if (l === 0) throw Error("jCarousel: No width/height set for items. This will cause an infinite loop. Aborting...");
                this.options.wrap != "circular" && this.options.size !== null && e > this.options.size ? m.push(h) : k && (i += l);
                n += l;
                if (n >= g) break;
                e++
            }
            for (h = 0; h < m.length; h++) m[h].remove();
            i > 0 && (this.list.css(this.wh, this.dimension(this.list) + i + "px"), d && (b -= i, this.list.css(this.lt, f.intval(this.list.css(this.lt)) - i + "px")));
            i = a + o - 1;
            if (this.options.wrap != "circular" && this.options.size && i > this.options.size) i = this.options.size;
            if (e > i) {
                o = 0;
                e = i;
                for (n = 0; ++o;) {
                    h = this.get(e--);
                    if (!h.length) break;
                    n += this.dimension(h);
                    if (n >= g) break
                }
            }
            e = i - o + 1;
            this.options.wrap != "circular" && e < 1 && (e = 1);
            if (this.inTail && d) b += this.tail, this.inTail = !1;
            this.tail = null;
            if (this.options.wrap != "circular" && i == this.options.size && i - o + 1 >= 1 && (d = f.intval(this.get(i).css(!this.options.vertical ? "marginRight" : "marginBottom")), n - d > g)) this.tail = n - g - d;
            if (c && a === this.options.size && this.tail) b -= this.tail, this.inTail = !0;
            for (; a-- > e;) b += this.dimension(this.get(a));
            this.prevFirst = this.first;
            this.prevLast = this.last;
            this.first = e;
            this.last = i;
            return b
        },
        animate: function (a, c) {
            if (!this.locked && !this.animating) {
                this.animating = !0;
                var b = this,
                    d = function () {
                        b.animating = !1;
                        a === 0 && b.list.css(b.lt, 0);
                        !b.autoStopped && (b.options.wrap == "circular" || b.options.wrap == "both" || b.options.wrap == "last" || b.options.size === null || b.last < b.options.size || b.last == b.options.size && b.tail !== null && !b.inTail) && b.startAuto();
                        b.buttons();
                        b.notify("onAfterAnimation");
                        if (b.options.wrap == "circular" && b.options.size !== null) for (var c = b.prevFirst; c <= b.prevLast; c++) c !== null && !(c >= b.first && c <= b.last) && (c < 1 || c > b.options.size) && b.remove(c)
                    };
                this.notify("onBeforeAnimation");
                if (!this.options.animation || c === !1) this.list.css(this.lt, a + "px"), d();
                else {
                    var f = !this.options.vertical ? this.options.rtl ? {
                        right: a
                    } : {
                        left: a
                    } : {
                        top: a
                    },
                        d = {
                            duration: this.options.animation,
                            easing: this.options.easing,
                            complete: d
                        };
                    if (g.isFunction(this.options.animationStepCallback)) d.step = this.options.animationStepCallback;
                    this.list.animate(f, d)
                }
            }
        },
        startAuto: function (a) {
            if (a !== void 0) this.options.auto = a;
            if (this.options.auto === 0) return this.stopAuto();
            if (this.timer === null) {
                this.autoStopped = !1;
                var c = this;
                this.timer = window.setTimeout(function () {
                    c.next()
                }, this.options.auto * 1E3)
            }
        },
        stopAuto: function () {
            this.pauseAuto();
            this.autoStopped = !0
        },
        pauseAuto: function () {
            if (this.timer !== null) window.clearTimeout(this.timer), this.timer = null
        },
        buttons: function (a, c) {
            if (a == null && (a = !this.locked && this.options.size !== 0 && (this.options.wrap && this.options.wrap != "first" || this.options.size === null || this.last < this.options.size), !this.locked && (!this.options.wrap || this.options.wrap == "first") && this.options.size !== null && this.last >= this.options.size)) a = this.tail !== null && !this.inTail;
            if (c == null && (c = !this.locked && this.options.size !== 0 && (this.options.wrap && this.options.wrap != "last" || this.first > 1), !this.locked && (!this.options.wrap || this.options.wrap == "last") && this.options.size !== null && this.first == 1)) c = this.tail !== null && this.inTail;
            var b = this;
            this.buttonNext.size() > 0 ? (this.buttonNext.unbind(this.options.buttonNextEvent + ".jcarousel", this.funcNext), a && this.buttonNext.bind(this.options.buttonNextEvent + ".jcarousel", this.funcNext), this.buttonNext[a ? "removeClass" : "addClass"](this.className("jcarousel-next-disabled")).attr("disabled", a ? !1 : !0), this.options.buttonNextCallback !== null && this.buttonNext.data("jcarouselstate") != a && this.buttonNext.each(function () {
                b.options.buttonNextCallback(b, this, a)
            }).data("jcarouselstate", a)) : this.options.buttonNextCallback !== null && this.buttonNextState != a && this.options.buttonNextCallback(b, null, a);
            this.buttonPrev.size() > 0 ? (this.buttonPrev.unbind(this.options.buttonPrevEvent + ".jcarousel", this.funcPrev), c && this.buttonPrev.bind(this.options.buttonPrevEvent + ".jcarousel", this.funcPrev), this.buttonPrev[c ? "removeClass" : "addClass"](this.className("jcarousel-prev-disabled")).attr("disabled", c ? !1 : !0), this.options.buttonPrevCallback !== null && this.buttonPrev.data("jcarouselstate") != c && this.buttonPrev.each(function () {
                b.options.buttonPrevCallback(b, this, c)
            }).data("jcarouselstate", c)) : this.options.buttonPrevCallback !== null && this.buttonPrevState != c && this.options.buttonPrevCallback(b, null, c);
            this.buttonNextState = a;
            this.buttonPrevState = c
        },
        notify: function (a) {
            var c = this.prevFirst === null ? "init" : this.prevFirst < this.first ? "next" : "prev";
            this.callback("itemLoadCallback", a, c);
            this.prevFirst !== this.first && (this.callback("itemFirstInCallback", a, c, this.first), this.callback("itemFirstOutCallback", a, c, this.prevFirst));
            this.prevLast !== this.last && (this.callback("itemLastInCallback", a, c, this.last), this.callback("itemLastOutCallback", a, c, this.prevLast));
            this.callback("itemVisibleInCallback", a, c, this.first, this.last, this.prevFirst, this.prevLast);
            this.callback("itemVisibleOutCallback", a, c, this.prevFirst, this.prevLast, this.first, this.last)
        },
        callback: function (a, c, b, d, f, j, e) {
            if (!(this.options[a] == null || typeof this.options[a] != "object" && c != "onAfterAnimation")) {
                var h = typeof this.options[a] == "object" ? this.options[a][c] : this.options[a];
                if (g.isFunction(h)) {
                    var i = this;
                    if (d === void 0) h(i, b, c);
                    else if (f === void 0) this.get(d).each(function () {
                        h(i, this, d, b, c)
                    });
                    else for (var a = function (a) {
                            i.get(a).each(function () {
                                h(i, this, a, b, c)
                            })
                        }, k = d; k <= f; k++) k !== null && !(k >= j && k <= e) && a(k)
                }
            }
        },
        create: function (a) {
            return this.format("<li></li>", a)
        },
        format: function (a, c) {
            for (var a = g(a), b = a.get(0).className.split(" "), d = 0; d < b.length; d++) b[d].indexOf("jcarousel-") != -1 && a.removeClass(b[d]);
            a.addClass(this.className("jcarousel-item")).addClass(this.className("jcarousel-item-" + c)).css({
                "float": this.options.rtl ? "right" : "left",
                "list-style": "none"
            }).attr("jcarouselindex", c);
            return a
        },
        className: function (a) {
            return a + " " + a + (!this.options.vertical ? "-horizontal" : "-vertical")
        },
        dimension: function (a, c) {
            var b = g(a);
            if (c == null) return !this.options.vertical ? b.outerWidth(!0) || f.intval(this.options.itemFallbackDimension) : b.outerHeight(!0) || f.intval(this.options.itemFallbackDimension);
            else {
                var d = !this.options.vertical ? c - f.intval(b.css("marginLeft")) - f.intval(b.css("marginRight")) : c - f.intval(b.css("marginTop")) - f.intval(b.css("marginBottom"));
                g(b).css(this.wh, d + "px");
                return this.dimension(b)
            }
        },
        clipping: function () {
            return !this.options.vertical ? this.clip[0].offsetWidth - f.intval(this.clip.css("borderLeftWidth")) - f.intval(this.clip.css("borderRightWidth")) : this.clip[0].offsetHeight - f.intval(this.clip.css("borderTopWidth")) - f.intval(this.clip.css("borderBottomWidth"))
        },
        index: function (a, c) {
            if (c == null) c = this.options.size;
            return Math.round(((a - 1) / c - Math.floor((a - 1) / c)) * c) + 1
        }
    });
    f.extend({
        defaults: function (a) {
            return g.extend(q, a || {})
        },
        intval: function (a) {
            a = parseInt(a, 10);
            return isNaN(a) ? 0 : a
        },
        windowLoaded: function () {
            m = !0
        }
    });
    g.fn.jcarousel = function (a) {
        if (typeof a == "string") {
            var c = g(this).data("jcarousel"),
                b = Array.prototype.slice.call(arguments, 1);
            return c[a].apply(c, b)
        } else return this.each(function () {
            var b = g(this).data("jcarousel");
            b ? (a && g.extend(b.options, a), b.reload()) : g(this).data("jcarousel", new f(this, a))
        })
    }
})(jQuery);

function stop_on_mouseover(carousel) {
    carousel.buttonNext.bind('click', function () {
        carousel.startAuto(0);
    });
    carousel.buttonPrev.bind('click', function () {
        carousel.startAuto(0);
    });
    carousel.clip.hover(function () {
        carousel.stopAuto();
    }, function () {
        carousel.startAuto();
    });
};
$(function () {
    $('ul.slide-hot-pr').jcarousel({
        visible: 3,
        auto: 3,
        wrap: 'last',
        buttonNextHTML: '<a href="javascript:;" class="next-slide">&nbsp;</a>',
        buttonPrevHTML: '<a href="javascript:;" class="prv-slide">&nbsp;</a>',
        initCallback: stop_on_mouseover
    });
    $(".dispImg.ftp").hover(function () {
        $(this).stop().animate({
            height: "333px"
        }, 400);
    }, function (elem) {
        $(this).stop().animate({
            height: "250px"
        }, 400);
    });
});

$(function () {
    if ( !! $('#shareBar').length) {
        var el = $('#shareBar');
        var stickyTop = $('#shareBar').offset().top;
        var footerTop = $('.stop-here').offset().top;
        var stickyHeight = $('#shareBar').height();
        var limit = footerTop - 20;
        $(window).scroll(function () {
            var topBillHeight = $('.topBill').height();
            var windowTop = $(window).scrollTop();
            if (stickyTop < windowTop) {
                if (topBillHeight) {
                    el.css({
                        position: 'fixed',
                        top: topBillHeight + 20
                    });
                } else {
                    el.css({
                        position: 'fixed',
                        top: 5
                    });
                }
            } else {
                if (topBillHeight) {
                    el.css({
                        position: 'absolute',
                        top: 337
                    });
                } else {
                    el.css('position', 'absolute');
                }
            }
            if (limit < windowTop) {
                var diff = limit - windowTop;
                el.css({
                    top: diff
                });
            }
        });
    }
});

$(function () {
    $('.close-coupon-popup').click(function () {
        $('.coupon-popup').addClass('hidden');
        return false;
    });
    $('.bgBottom').click(function () {
        $('.coupon-popup').toggleClass('hidden');
        return false;
    });
    $('.coupon-popup input[type="text"]').focusin(function () {
        var value_default = $(this).data('val');
        if ($(this).val() == value_default) $(this).val('');
    }).focusout(function () {
        var value_default = $(this).data('val');
        if ($(this).val() == '') $(this).val(value_default);
        else return false;
    });
    $('.register-coupon').click(function () {
        return false;
    });
    $('.onetop-share').click(function () {
        var obj = {
            method: 'feed',
            link: 'http://www.1top.vn',
            picture: 'http://www.1top.vn/webskins/skins/frontend/images/fb-logo.png',
            name: '1Top',
            caption: 'Khuyến mại mỗi ngày với hàng ngàn sản phẩm chất lượng',
            description: 'Sàn khuyến mại, giảm giá nhiều hàng số 1 Việt Nam với hàng ngàn sản phẩm giảm giá mỗi ngày từ những người bán uy tín.'
        };

        function callback(response) {
            document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
        }
        FB.ui(obj, callback);
    });
    $('.register-coupon').click(function () {
        var tm;
        var elem = $(this);
        if (elem.hasClass('disabled')) return false;
        var data = $('#coupon_form').serialize();
        $.ajax({
            beforeSend: function () {
                elem.addClass('disabled');
            },
            url: 'ajax/frontend/coupon_ajax/register',
            type: 'POST',
            dataType: 'json',
            data: data,
            success: function (data) {
                elem.removeClass('disabled');
                if (data.err == 1) {
                    $('.coupon-notice').html(data.msg);
                } else {
                    window.clearTimeout(tm);
                    $('.coupon-notice').html(data.msg);
                    tm = setTimeout(function () {
                        $('.coupon-popup').addClass('hidden');
                    }, 2000);
                }
            }
        });
    });
});